package com.edu.exam.entity.grading.integration;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import java.time.LocalDateTime;

/**
 * 系统配置实体类
 *
 * <p>所属模块：B-06 成绩管理模块</p>
 * <p>对应数据库表：system_config</p>
 *
 * <p>存储系统配置参数</p>
 *
 * @author G-09 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
@Entity
@Table(name = "system_config")
@Data
@EqualsAndHashCode(callSuper = false)
public class SystemConfig {

    @Id
    @Column(name = "config_id", length = 64)
    private String configId;

    @Column(name = "config_category", length = 32, nullable = false)
    private String configCategory;

    @Column(name = "config_key", length = 128, nullable = false)
    private String configKey;

    @Column(name = "config_value", columnDefinition = "TEXT")
    private String configValue;

    @Column(name = "config_type", length = 32, nullable = false)
    private String configType;

    @Column(name = "description", length = 255)
    private String description;

    @Column(name = "is_encrypted", nullable = false)
    private Boolean isEncrypted = false;

    @Column(name = "is_system", nullable = false)
    private Boolean isSystem = false;

    @Column(name = "status", length = 32, nullable = false)
    private String status;

    @Column(name = "created_by", length = 64)
    private String createdBy;

    @CreationTimestamp
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    @Column(name = "updated_by", length = 64)
    private String updatedBy;

    @UpdateTimestamp
    @Column(name = "updated_time")
    private LocalDateTime updatedTime;

    @Version
    @Column(name = "version", nullable = false)
    private Integer version = 1;

    @PrePersist
    protected void onCreate() {
        if (status == null) {
            status = "active";
        }
        if (isEncrypted == null) {
            isEncrypted = false;
        }
        if (isSystem == null) {
            isSystem = false;
        }
        if (version == null) {
            version = 1;
        }
    }
}